--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * File containing the base import form.
+ *
+ * @package tool_uploadcourse
+ * @copyright 2013 Frédéric Massart
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+require_once($CFG->libdir.'/formslib.php');
+
+/**
+ * Base import form.
+ *
+ * @package tool_uploadcourse
+ * @copyright 2013 Frédéric Massart
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class tool_uploadcourse_base_form extends moodleform {
+
+ /**
+ * Empty definition.
+ *
+ * @return void
+ */
+ public function definition() {
+ }
+
+ /**
+ * Adds the import settings part.
+ *
+ * @return void
+ */
+ public function add_import_options() {
+ $mform = $this->_form;
+
+ // Upload settings and file.
+ $mform->addElement('header', 'importoptionshdr', get_string('importoptions', 'tool_uploadcourse'));
+ $mform->setExpanded('importoptionshdr', true);
+
+ $choices = array(
+ tool_uploadcourse_processor::MODE_CREATE_NEW => get_string('ccoptype_addnew', 'tool_uploadcourse'),
+ tool_uploadcourse_processor::MODE_CREATE_ALL => get_string('ccoptype_addinc', 'tool_uploadcourse'),
+ tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE => get_string('ccoptype_addupdate', 'tool_uploadcourse'),
+ tool_uploadcourse_processor::MODE_UPDATE_ONLY => get_string('ccoptype_update', 'tool_uploadcourse')
+ );
+ $mform->addElement('select', 'options[mode]', get_string('mode', 'tool_uploadcourse'), $choices);
+
+ $choices = array(
+ tool_uploadcourse_processor::UPDATE_NOTHING => get_string('nochanges', 'tool_uploadcourse'),
+ tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY => get_string('ccupdatefromfile', 'tool_uploadcourse'),
+ tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_OR_DEFAUTLS => get_string('ccupdateall', 'tool_uploadcourse'),
+ tool_uploadcourse_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS => get_string('ccupdatemissing', 'tool_uploadcourse')
+ );
+ $mform->addElement('select', 'options[updatemode]', get_string('updatemode', 'tool_uploadcourse'), $choices);
+ $mform->setDefault('options[updatemode]', tool_uploadcourse_processor::UPDATE_NOTHING);
+ $mform->disabledIf('options[updatemode]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
+ $mform->disabledIf('options[updatemode]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
+
+ $mform->addElement('selectyesno', 'options[allowdeletes]', get_string('allowdeletes', 'tool_uploadcourse'));
+ $mform->setDefault('options[allowdeletes]', 0);
+ $mform->disabledIf('options[allowdeletes]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
+ $mform->disabledIf('options[allowdeletes]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
+
+ $mform->addElement('selectyesno', 'options[allowrenames]', get_string('allowrenames', 'tool_uploadcourse'));
+ $mform->setDefault('options[allowrenames]', 0);
+ $mform->disabledIf('options[allowrenames]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
+ $mform->disabledIf('options[allowrenames]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
+
+ $mform->addElement('selectyesno', 'options[allowresets]', get_string('allowresets', 'tool_uploadcourse'));
+ $mform->setDefault('options[allowresets]', 0);
+ $mform->disabledIf('options[allowresets]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
+ $mform->disabledIf('options[allowresets]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
+ }
+
+}
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir.'/formslib.php');
-
/**
* Specify course upload details.
*
* @copyright 2011 Piers Harding
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_uploadcourse_step2_form extends moodleform {
+class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
/**
* The standard form definiton.
$data = $this->_customdata['data'];
$courseconfig = get_config('moodlecourse');
- // Upload settings and file.
- $mform->addElement('header', 'generalhdr', get_string('general'));
-
- $choices = array(
- tool_uploadcourse_processor::MODE_CREATE_NEW => get_string('ccoptype_addnew', 'tool_uploadcourse'),
- tool_uploadcourse_processor::MODE_CREATE_ALL => get_string('ccoptype_addinc', 'tool_uploadcourse'),
- tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE => get_string('ccoptype_addupdate', 'tool_uploadcourse'),
- tool_uploadcourse_processor::MODE_UPDATE_ONLY => get_string('ccoptype_update', 'tool_uploadcourse')
- );
- $mform->addElement('select', 'options[mode]', get_string('mode', 'tool_uploadcourse'), $choices);
-
- $choices = array(
- tool_uploadcourse_processor::UPDATE_NOTHING => get_string('nochanges', 'tool_uploadcourse'),
- tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY => get_string('ccupdatefromfile', 'tool_uploadcourse'),
- tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_OR_DEFAUTLS => get_string('ccupdateall', 'tool_uploadcourse'),
- tool_uploadcourse_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS => get_string('ccupdatemissing', 'tool_uploadcourse')
- );
- $mform->addElement('select', 'options[updatemode]', get_string('updatemode', 'tool_uploadcourse'), $choices);
- $mform->setDefault('options[updatemode]', tool_uploadcourse_processor::UPDATE_NOTHING);
- $mform->disabledIf('options[updatemode]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
- $mform->disabledIf('options[updatemode]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
-
- $mform->addElement('selectyesno', 'options[allowdeletes]', get_string('allowdeletes', 'tool_uploadcourse'));
- $mform->setDefault('options[allowdeletes]', 0);
- $mform->disabledIf('options[allowdeletes]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
- $mform->disabledIf('options[allowdeletes]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
-
- $mform->addElement('selectyesno', 'options[allowrenames]', get_string('allowrenames', 'tool_uploadcourse'));
- $mform->setDefault('options[allowrenames]', 0);
- $mform->disabledIf('options[allowrenames]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
- $mform->disabledIf('options[allowrenames]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
-
- $mform->addElement('selectyesno', 'options[allowresets]', get_string('allowresets', 'tool_uploadcourse'));
- $mform->setDefault('options[allowresets]', 0);
- $mform->disabledIf('options[allowresets]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
- $mform->disabledIf('options[allowresets]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
+ // Import options.
+ $this->add_import_options();
+
+ // Course options.
+ $mform->addElement('header', 'courseoptionshdr', get_string('courseprocess', 'tool_uploadcourse'));
+ $mform->setExpanded('courseoptionshdr', true);
+
+ $mform->addElement('text', 'options[shortnametemplate]', get_string('shortnametemplate', 'tool_uploadcourse'), 'maxlength="100" size="20"');
+ $mform->setType('options[shortnametemplate]', PARAM_RAW);
+ $mform->addHelpButton('options[shortnametemplate]', 'shortnametemplate', 'tool_uploadcourse');
+ $mform->disabledIf('options[shortnametemplate]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE);
+ $mform->disabledIf('options[shortnametemplate]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_UPDATE_ONLY);
+
+ $contextid = $this->_customdata['contextid'];
+ $mform->addElement('hidden', 'contextid', $contextid);
+ $mform->setType('contextid', PARAM_INT);
+ $mform->addElement('filepicker', 'options[restorefile]', get_string('templatefile', 'tool_uploadcourse'));
+ $mform->addHelpButton('options[restorefile]', 'templatefile', 'tool_uploadcourse');
+
+ $mform->addElement('text', 'options[templatecourse]', get_string('coursetemplatename', 'tool_uploadcourse'));
+ $mform->setType('options[templatecourse]', PARAM_TEXT);
+ $mform->addHelpButton('options[templatecourse]', 'coursetemplatename', 'tool_uploadcourse');
$mform->addElement('selectyesno', 'options[reset]', get_string('reset', 'tool_uploadcourse'));
$mform->setDefault('options[reset]', 0);
- $mform->disabledIf('options[reset]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
- $mform->disabledIf('options[reset]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
+ $mform->disabledIf('options[reset]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
+ $mform->disabledIf('options[reset]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
+ $mform->disabledIf('options[reset]', 'options[allowresets]', 'eq', 0);
// Default values.
$mform->addElement('header', 'defaultheader', get_string('defaultvalues', 'tool_uploadcourse'));
$mform->setExpanded('defaultheader', true);
- $mform->addElement('text', 'options[shortnametemplate]', get_string('shortnametemplate', 'tool_uploadcourse'), 'maxlength="100" size="20"');
- $mform->setType('options[shortnametemplate]', PARAM_RAW);
- $mform->addHelpButton('options[shortnametemplate]', 'shortnametemplate', 'tool_uploadcourse');
- $mform->disabledIf('options[shortnametemplate]', 'mode', 'eq', tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE);
- $mform->disabledIf('options[shortnametemplate]', 'mode', 'eq', tool_uploadcourse_processor::MODE_UPDATE_ONLY);
-
$displaylist = coursecat::make_categories_list('moodle/course:create');
$mform->addElement('select', 'defaults[category]', get_string('coursecategory'), $displaylist);
$mform->addHelpButton('defaults[category]', 'coursecategory');
$choices['1'] = get_string('show');
$mform->addElement('select', 'defaults[visible]', get_string('visible'), $choices);
$mform->addHelpButton('defaults[visible]', 'visible');
- $mform->setDefault('defaults[defaults]', $courseconfig->visible);
+ $mform->setDefault('defaults[visible]', $courseconfig->visible);
$mform->addElement('date_selector', 'defaults[startdate]', get_string('startdate'));
$mform->addHelpButton('defaults[startdate]', 'startdate');
$mform->addHelpButton('defaults[groupmodeforce]', 'groupmodeforce', 'group');
$mform->setDefault('defaults[groupmodeforce]', $courseconfig->groupmodeforce);
- // Restore.
- $mform->addElement('header', 'restorehdr', get_string('restoreafterimport', 'tool_uploadcourse'));
- $mform->setExpanded('restorehdr', true);
-
- $courseshortnames = $DB->get_records('course', null, $sort='shortname', 'id,shortname,idnumber');
- $formccourseshortnames = array('' => get_string('none'));
- foreach ($courseshortnames as $course) {
- $formccourseshortnames[$course->shortname] = $course->shortname;
- }
- $mform->addElement('select', 'options[templatecourse]', get_string('coursetemplatename', 'tool_uploadcourse'), $formccourseshortnames);
- $mform->addHelpButton('options[templatecourse]', 'coursetemplatename', 'tool_uploadcourse');
- $mform->setDefault('options[templatecourse]', 'none');
-
- $contextid = $this->_customdata['contextid'];
- $mform->addElement('hidden', 'contextid', $contextid);
- $mform->setType('contextid', PARAM_INT);
- $mform->addElement('filepicker', 'options[restorefile]', get_string('templatefile', 'tool_uploadcourse'));
-
// Hidden fields.
$mform->addElement('hidden', 'iid');
$mform->setType('iid', PARAM_INT);
function add_action_buttons($cancel = true, $submitlabel = null){
$mform =& $this->_form;
$buttonarray = array();
- $buttonarray[] = &$mform->createElement('submit', 'previewbutton', get_string('preview', 'tool_uploadcourse'));
+ $buttonarray[] = &$mform->createElement('submit', 'showpreview', get_string('preview', 'tool_uploadcourse'));
$buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$string['coursedeleted'] = 'Course deleted';
$string['coursedeletionnotallowed'] = 'Course deletion is not allowed';
$string['coursedoesnotexistandcreatenotallowed'] = 'The course does not exist and creating course is not allowed';
-$string['courseexistsanduploadnotallowed'] = 'The course exists and update are not allowed';
+$string['courseexistsanduploadnotallowed'] = 'The course exists and update is not allowed';
$string['courseidnumberincremented'] = 'Course ID number incremented {$a->from} -> {$a->to}';
+$string['courseprocess'] = 'Course process';
$string['courserenamed'] = 'Course renamed';
$string['courserenamingnotallowed'] = 'Course renaming is not allowed';
$string['coursereset'] = 'Course reset';
$string['courseserrors'] = 'Courses errors: {$a}';
$string['courseshortnameincremented'] = 'Course shortname incremented {$a->from} -> {$a->to}';
$string['courseshortnamegenerated'] = 'Course shortname generated: {$a}';
+$string['coursetemplatename'] = 'Restore from this course after upload';
+$string['coursetemplatename_help'] = 'Enter an existing course shortname to use as a template for the creation of all courses.';
$string['coursetorestorefromdoesnotexist'] = 'The course to restore from does not exist';
$string['courseupdated'] = 'Course updated';
$string['csvdelimiter'] = 'CSV delimiter';
$string['csvfileerror'] = 'There is something wrong with the format of the CSV file. Please check the number of headings and columns match, and that the delimiter and file encoding are correct: {$a}';
$string['csvline'] = 'Line';
-$string['defaultvalues'] = 'Default values';
+$string['defaultvalues'] = 'Default course values';
$string['encoding'] = 'Encoding';
$string['errorwhilerestoringcourse'] = 'Error while restoring the course';
$string['errorwhiledeletingcourse'] = 'Error while deleting the course';
$string['generatedshortnameinvalid'] = 'The generated shortname is invalid';
$string['generatedshortnamealreadyinuse'] = 'The generated shortname is already in use';
$string['id'] = 'ID';
+$string['importoptions'] = 'Import options';
$string['idnumberalreadyinuse'] = 'ID number already used by a course';
$string['invalidbackupfile'] = 'Invalid backup file';
$string['invalidcourseformat'] = 'Invalid course format';
$string['result'] = 'Result';
$string['restoreafterimport'] = 'Restore after import';
$string['rowpreviewnum'] = 'Preview rows';
-$string['shortnametemplate'] = 'Shortname template';
+$string['shortnametemplate'] = 'Template to generate a shortname';
$string['shortnametemplate_help'] = 'The short name of the course is displayed in the navigation. You may use template syntax here (%f = fullname, %i = idnumber), or enter an initial value that is incremented.';
+$string['templatefile'] = 'Restore from this file after upload';
+$string['templatefile_help'] = 'Select a file to use as a template for the creation of all courses.';
$string['unknownimportmode'] = 'Unknown import mode';
$string['updatemode'] = 'Update mode';
$string['updatemodedoessettonothing'] = 'Update mode does not allow anything to be updated';
$string['invalidcategory'] = 'Invalid category';
-$string['coursetemplatename'] = 'Course template shortname';
-$string['coursetemplatename_help'] = 'Select an existing course shortname to use as a template for the creation of all courses.';
-$string['templatefile'] = 'Template backup file';
$string['invalidbackupfile'] = 'Invalid backup file';