# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: moodle/question/format.php --- moodle/question/format.php Base (1.35.2.11) +++ moodle/question/format.php Locally Modified (Based On 1.35.2.11) @@ -16,6 +16,9 @@ var $course = NULL; var $filename = ''; var $realfilename = ''; + var $filetype = ''; // dlnsk %%18%% + var $filesize = ''; // dlnsk %%18%% + var $option = array(); // dlnsk %%39%% var $matchgrades = 'error'; var $catfromfile = 0; var $contextfromfile = 0; @@ -90,6 +93,23 @@ } /** + * set the file options + * @param array file options of file from uploadmanager + */ + function setFileOptions( $file ) { // dlnsk %%18%% + $this->filetype = $file['type']; + $this->filesize = isset($file['size']) ? $file['size'] : ''; + } + + /** + * Set additional options depended of format + * @param array aditional options + */ + function setOptions( $options ) { // dlnsk %%39%% + $this->option = $options; + } + + /** * set the "real" filename * (this is what the user typed, regardless of wha happened next) * @param string realfilename name of file as typed by user Index: moodle/question/import.php --- moodle/question/import.php Base (1.46.2.4) +++ moodle/question/import.php Locally Modified (Based On 1.46.2.4) @@ -14,6 +14,7 @@ require_once($CFG->libdir . '/uploadlib.php'); require_once($CFG->libdir . '/questionlib.php'); require_once("import_form.php"); + require_once("import_select_form.php"); // dlnsk %%39%% list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('import', false, false); @@ -43,12 +44,6 @@ // ensure the files area exists for this course make_upload_directory("$COURSE->id"); - $import_form = new question_import_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('import'), - 'defaultcategory'=>$pagevars['cat'])); - - if ($import_form->is_cancelled()){ - redirect($thispageurl); - } //========== // PAGE HEADER //========== @@ -80,7 +75,31 @@ include('tabs.php'); } + // dlnsk %%39%% + $select_form = new question_import_select_form($thispageurl); + if ($sform = $select_form->get_data()) { + $classname = get_classname($sform->format); + $import_form = new $classname($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('import'), + 'defaultcategory'=>$pagevars['cat'], 'format'=>$sform->format)); + print_heading_with_help($txt->importquestions, 'import', 'quiz'); + $import_form->display(); + print_footer($COURSE); + exit; + } + + if ($format = optional_param('format')) { + $classname = get_classname($format); + $import_form = new $classname($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('import'), + 'defaultcategory'=>$pagevars['cat'], 'format'=>$format)); + } else { + print_heading_with_help($txt->importquestions, "import", "quiz"); + /// Print first form + $select_form->display(); + print_footer($COURSE); + exit; + } + // file upload form sumitted if ($form = $import_form->get_data()) { @@ -94,6 +113,7 @@ $realfilename = $form->choosefile; if (file_exists($importfile)) { $fileisgood = true; + $fileoptions['type'] = mimeinfo('type', $importfile); //dlnsk %%18%% } else { print_error('uploadproblem', 'moodle', $form->choosefile); } @@ -104,6 +124,7 @@ print_error('uploadproblem', 'moodle'); }else { $fileisgood = true; + $fileoptions = $import_form->get_importfile_options(); //dlnsk %%18%% } } @@ -126,11 +147,21 @@ $qformat->setCourse($COURSE); $qformat->setFilename($importfile); $qformat->setRealfilename($realfilename); + $qformat->setFileOptions($fileoptions); //dlnsk %%18%% $qformat->setMatchgrades($form->matchgrades); $qformat->setCatfromfile(!empty($form->catfromfile)); $qformat->setContextfromfile(!empty($form->contextfromfile)); $qformat->setStoponerror($form->stoponerror); + $arr_form = (array)$form; + $options = array(); + foreach($arr_form as $key => $value) { // getting additional parameters (dlnsk %%39%%) + if(substr($key,0,4) == 'fao_') { + $options[substr($key,4)] = $value; + } + } + $qformat->setOptions($options); + // Do anything before that we need to if (! $qformat->importpreprocess()) { print_error('importerror', 'quiz', $thispageurl->out()); @@ -159,4 +190,18 @@ $import_form->display(); print_footer($COURSE); + +function get_classname($format) { // dlnsk %%39%% + + $classname = 'question_import_form'; + if (is_readable("format/$format/import_form.php")) { + require_once("format/$format/import_form.php"); + + if (class_exists("{$format}_import_form")) { + $classname = "{$format}_import_form"; + } + } + return $classname; +} + ?> Index: moodle/question/import_form.php --- moodle/question/import_form.php Base (1.5.2.3) +++ moodle/question/import_form.php Locally Modified (Based On 1.5.2.3) @@ -4,27 +4,33 @@ class question_import_form extends moodleform { + // Render part of second's step form for getting additional format dependent options + // Name of each parameter should start from 'fao_' (format's additional option) + // You should override this method in your format's import form class + function additionalOptions(&$form) { + $form->addElement('header', 'formatoptions', get_string('formatoptions','quiz')); + return false; + } + + // DO NOT OVERRIDE 'definition' function in your subclass! + // Use 'additionalOptions' function for add your own options in + // second's step form of import questions function definition() { global $COURSE; $mform =& $this->_form; $defaultcategory = $this->_customdata['defaultcategory']; $contexts = $this->_customdata['contexts']; + $format = $this->_customdata['format']; //dlnsk %%39%% //-------------------------------------------------------------------------------- - $mform->addElement('header','fileformat', get_string('fileformat','quiz')); - $fileformatnames = get_import_export_formats('import'); - $radioarray = array(); - foreach ($fileformatnames as $id => $fileformatname) { - $radioarray[] = &MoodleQuickForm::createElement('radio','format','',$fileformatname,$id ); - } - $mform->addGroup($radioarray,'format', '', array('
'), false); - $mform->addRule('format', null, 'required', null, 'client' ); - $mform->setHelpButton('format', array('import', get_string('importquestions', 'quiz'), 'quiz')); +// $mform->addElement('static', 'formatdesc', get_string('fileformat', 'quiz'), get_string($format, 'quiz')); //-------------------------------------------------------------------------------- $mform->addElement('header','general', get_string('general', 'form')); + $mform->addElement('hidden', 'format', $format); //dlnsk %%39%% + $mform->addElement('questioncategory', 'category', get_string('category','quiz'), compact('contexts')); $mform->setDefault('category', $defaultcategory); $mform->setHelpButton('category', array('importcategory', get_string('importcategory','quiz'), 'quiz')); @@ -50,6 +56,12 @@ $mform->setHelpButton('stoponerror', array('stoponerror', get_string('stoponerror', 'quiz'), 'quiz')); //-------------------------------------------------------------------------------- + // Adding format dependent options //dlnsk %%39%% + if (!$this->additionalOptions($mform)) { + $mform->addElement('static', 'noformatoptions', '', get_string('noformatoptions','quiz')); + } + +//-------------------------------------------------------------------------------- $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz')); $this->set_upload_manager(new upload_manager('newfile', true, false, $COURSE, false, 0, false, true, false)); @@ -69,6 +81,7 @@ $mform->addElement('static', 'dummy', ''); $mform->closeHeaderBefore('dummy'); } + function get_importfile_name(){ if ($this->is_submitted() and $this->is_validated()) { // return the temporary filename to process @@ -86,5 +99,14 @@ return NULL; } } + + function get_importfile_options(){ //dlnsk %%18%% + if ($this->is_submitted() and $this->is_validated()) { + // return the temporary filename to process + return $this->_upload_manager->files['newfile']; + }else{ + return NULL; } + } +} ?> Index: moodle/question/import_select_form.php --- moodle/question/import_select_form.php No Base Revision +++ moodle/question/import_select_form.php Locally New @@ -0,0 +1,27 @@ +libdir.'/formslib.php'); + +//First step in import question process +class question_import_select_form extends moodleform { // dlnsk %%39%% + + function definition() { + global $COURSE; + $mform =& $this->_form; + +//-------------------------------------------------------------------------------- + $mform->addElement('header','fileformat', get_string('fileformat','quiz')); + $fileformatnames = get_import_export_formats('import'); + $radioarray = array(); + foreach ($fileformatnames as $id => $fileformatname) { + $radioarray[] = &MoodleQuickForm::createElement('radio','format','',$fileformatname,$id ); + } + $mform->addGroup($radioarray,'format', '', array('
'), false); + $mform->addRule('format', null, 'required', null, 'client' ); + $mform->setHelpButton('format', array('import', get_string('importquestions', 'quiz'), 'quiz')); + +//-------------------------------------------------------------------------------- + $this->add_action_buttons(false, get_string('next')); + } +} +?>