[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/question/ -> import_form.php (source)

   1  <?php  // $Id$
   2  
   3  require_once($CFG->libdir.'/formslib.php');
   4  
   5  class question_import_form extends moodleform {
   6  
   7      function definition() {
   8          global $COURSE;
   9          $mform    =& $this->_form;
  10  
  11          $defaultcategory   = $this->_customdata['defaultcategory'];
  12          $contexts   = $this->_customdata['contexts'];
  13  
  14  //--------------------------------------------------------------------------------
  15          $mform->addElement('header','fileformat', get_string('fileformat','quiz'));
  16          $fileformatnames = get_import_export_formats('import');
  17          $radioarray = array();
  18          foreach ($fileformatnames as $id => $fileformatname) {
  19              $radioarray[] = &MoodleQuickForm::createElement('radio','format','',$fileformatname,$id );
  20          }
  21          $mform->addGroup($radioarray,'format', '', array('<br />'), false);
  22          $mform->addRule('format', null, 'required', null, 'client' );
  23          $mform->setHelpButton('format', array('import', get_string('importquestions', 'quiz'), 'quiz'));
  24  
  25  //--------------------------------------------------------------------------------
  26          $mform->addElement('header','general', get_string('general', 'form'));
  27  
  28          $mform->addElement('questioncategory', 'category', get_string('category','quiz'), compact('contexts'));
  29          $mform->setDefault('category', $defaultcategory);
  30          $mform->setHelpButton('category', array('importcategory', get_string('importcategory','quiz'), 'quiz'));
  31  
  32          $categorygroup = array();
  33          $categorygroup[] =& $mform->createElement('checkbox', 'catfromfile', '', get_string('getcategoryfromfile', 'question'));
  34          $categorygroup[] =& $mform->createElement('checkbox', 'contextfromfile', '', get_string('getcontextfromfile', 'question'));
  35          $mform->addGroup($categorygroup, 'categorygroup', '', '', false);
  36          $mform->disabledIf('categorygroup', 'catfromfile', 'notchecked');
  37          $mform->setDefault('catfromfile', 1);
  38          $mform->setDefault('contextfromfile', 1);
  39  
  40  
  41          $matchgrades = array();
  42          $matchgrades['error'] = get_string('matchgradeserror','quiz');
  43          $matchgrades['nearest'] = get_string('matchgradesnearest','quiz');
  44          $mform->addElement('select', 'matchgrades', get_string('matchgrades','quiz'), $matchgrades);
  45          $mform->setHelpButton('matchgrades', array('matchgrades', get_string('matchgrades','quiz'), 'quiz'));
  46          $mform->setDefault('matchgrades', 'error');
  47  
  48          $mform->addElement('selectyesno', 'stoponerror', get_string('stoponerror', 'quiz'));
  49          $mform->setDefault('stoponerror', 1);
  50          $mform->setHelpButton('stoponerror', array('stoponerror', get_string('stoponerror', 'quiz'), 'quiz'));
  51  
  52  //--------------------------------------------------------------------------------
  53          $mform->addElement('header', 'importfileupload', get_string('importfileupload','quiz'));
  54  
  55          $this->set_upload_manager(new upload_manager('newfile', true, false, $COURSE, false, 0, false, true, false));
  56          $mform->addElement('file', 'newfile', get_string('upload'));
  57  //--------------------------------------------------------------------------------
  58          $mform->addElement('submit', 'submitbutton', get_string('uploadthisfile'));
  59  
  60  //--------------------------------------------------------------------------------
  61          if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $COURSE->id))){
  62              $mform->addElement('header', 'importfilearea', get_string('importfilearea','quiz'));
  63  
  64              $mform->addElement('choosecoursefile', 'choosefile', get_string('choosefile','quiz'));
  65  //--------------------------------------------------------------------------------
  66              $mform->addElement('submit', 'submitbutton', get_string('importfromthisfile','quiz'));
  67          }
  68  //--------------------------------------------------------------------------------
  69          $mform->addElement('static', 'dummy', '');
  70          $mform->closeHeaderBefore('dummy');
  71      }
  72      function get_importfile_name(){
  73          if ($this->is_submitted() and $this->is_validated()) {
  74              // return the temporary filename to process
  75              return $this->_upload_manager->files['newfile']['tmp_name'];
  76          }else{
  77              return  NULL;
  78          }
  79      }
  80      
  81      function get_importfile_realname(){
  82          if ($this->is_submitted() and $this->is_validated()) {
  83              // return the temporary filename to process
  84              return $this->_upload_manager->files['newfile']['name'];
  85          }else{
  86              return  NULL;
  87          }
  88      }
  89  }
  90  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7