MDL-23479 backup - chat revised & old code deleted (but non-existing restore logs)
[moodle.git] / question / import_form.php
CommitLineData
aeb15530 1<?php
515ed4c3 2
bfebaf64
MD
3if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
5}
6
515ed4c3 7require_once($CFG->libdir.'/formslib.php');
515ed4c3 8
9class question_import_form extends moodleform {
10
11 function definition() {
12 global $COURSE;
13 $mform =& $this->_form;
14
15 $defaultcategory = $this->_customdata['defaultcategory'];
16 $contexts = $this->_customdata['contexts'];
45b68eef 17
18//--------------------------------------------------------------------------------
19 $mform->addElement('header','fileformat', get_string('fileformat','quiz'));
20 $fileformatnames = get_import_export_formats('import');
a387e8ac 21 $i = 0 ;
f94902db 22 foreach ($fileformatnames as $shortname => $fileformatname) {
a387e8ac 23 $currentgrp1 = array();
4b7c96d9 24 $currentgrp1[] = &$mform->createElement('radio','format','',$fileformatname,$shortname);
a387e8ac 25 $mform->addGroup($currentgrp1,"formathelp[$i]",'',array('<br />'),false);
4b7c96d9 26 $mform->setHelpButton("formathelp[$i]", array("$shortname",$fileformatname,"qformat_$shortname"));
a387e8ac 27 $i++ ;
45b68eef 28 }
a387e8ac 29 $mform->addRule("formathelp[0]", null, 'required', null, 'client' );
515ed4c3 30//--------------------------------------------------------------------------------
31 $mform->addElement('header','general', get_string('general', 'form'));
32
33 $mform->addElement('questioncategory', 'category', get_string('category','quiz'), compact('contexts'));
34 $mform->setDefault('category', $defaultcategory);
35 $mform->setHelpButton('category', array('importcategory', get_string('importcategory','quiz'), 'quiz'));
36
37 $categorygroup = array();
38 $categorygroup[] =& $mform->createElement('checkbox', 'catfromfile', '', get_string('getcategoryfromfile', 'question'));
39 $categorygroup[] =& $mform->createElement('checkbox', 'contextfromfile', '', get_string('getcontextfromfile', 'question'));
40 $mform->addGroup($categorygroup, 'categorygroup', '', '', false);
41 $mform->disabledIf('categorygroup', 'catfromfile', 'notchecked');
42 $mform->setDefault('catfromfile', 1);
43 $mform->setDefault('contextfromfile', 1);
44
515ed4c3 45
46 $matchgrades = array();
47 $matchgrades['error'] = get_string('matchgradeserror','quiz');
48 $matchgrades['nearest'] = get_string('matchgradesnearest','quiz');
49 $mform->addElement('select', 'matchgrades', get_string('matchgrades','quiz'), $matchgrades);
50 $mform->setHelpButton('matchgrades', array('matchgrades', get_string('matchgrades','quiz'), 'quiz'));
51 $mform->setDefault('matchgrades', 'error');
52
53 $mform->addElement('selectyesno', 'stoponerror', get_string('stoponerror', 'quiz'));
54 $mform->setDefault('stoponerror', 1);
55 $mform->setHelpButton('stoponerror', array('stoponerror', get_string('stoponerror', 'quiz'), 'quiz'));
15b83581 56
515ed4c3 57//--------------------------------------------------------------------------------
a1eb90c0 58 $mform->addElement('header', 'importfileupload', get_string('importfromthisfile','quiz'));
515ed4c3 59
a1eb90c0 60 $mform->addElement('filepicker', 'newfile', get_string('import', 'quiz'));
515ed4c3 61//--------------------------------------------------------------------------------
a1eb90c0 62 $mform->addElement('submit', 'submitbutton', get_string('import', 'quiz'));
515ed4c3 63
64//--------------------------------------------------------------------------------
a1eb90c0
DC
65 //if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $COURSE->id))){
66 //$mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz'));
67 //TODO: MDL-16094
4b7c96d9 68 //$mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz'));
515ed4c3 69//--------------------------------------------------------------------------------
a1eb90c0
DC
70 //$mform->addElement('submit', 'submitbutton', get_string('importfromthisfile','quiz'));
71 //}
515ed4c3 72//--------------------------------------------------------------------------------
8b66a42a 73 $mform->addElement('static', 'dummy', '');
74 $mform->closeHeaderBefore('dummy');
aeb15530
PS
75
76 // set a template for the format select elements
79e3dd8e 77 $renderer =& $mform->defaultRenderer();
78 $template = "{help} {element}\n";
79 $renderer->setGroupElementTemplate($template, 'format');
515ed4c3 80 }
515ed4c3 81}
aeb15530 82