MDL-22388 Added some checks to kill these scripts dead with an unequivocal notice...
[moodle.git] / mod / assignment / mod_form.php
1 <?php
2 if (!defined('MOODLE_INTERNAL')) {
3     die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
4 }
6 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
8 class mod_assignment_mod_form extends moodleform_mod {
10     function definition() {
11         global $CFG, $DB;
12         $mform =& $this->_form;
14         // this hack is needed for different settings of each subtype
15         if (!empty($this->_instance)) {
16             if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) {
17                 $type = $ass->assignmenttype;
18             } else {
19                 print_error('invalidassignment', 'assignment');
20             }
21         } else {
22             $type = required_param('type', PARAM_ALPHA);
23         }
24         $mform->addElement('hidden', 'assignmenttype', $type);
25         $mform->setType('assignmenttype', PARAM_ALPHA);
26         $mform->setDefault('assignmenttype', $type);
27         $mform->addElement('hidden', 'type', $type);
28         $mform->setType('type', PARAM_ALPHA);
29         $mform->setDefault('type', $type);
31         require($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
32         $assignmentclass = 'assignment_'.$type;
33         $assignmentinstance = new $assignmentclass();
35 //-------------------------------------------------------------------------------
36         $mform->addElement('header', 'general', get_string('general', 'form'));
38 //        $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
40         $mform->addElement('text', 'name', get_string('assignmentname', 'assignment'), array('size'=>'64'));
41         if (!empty($CFG->formatstringstriptags)) {
42             $mform->setType('name', PARAM_TEXT);
43         } else {
44             $mform->setType('name', PARAM_CLEAN);
45         }
46         $mform->addRule('name', null, 'required', null, 'client');
48         $this->add_intro_editor(true, get_string('description', 'assignment'));
50         $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'assignment'), array('optional'=>true));
51         $mform->setDefault('timeavailable', time());
52         $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'assignment'), array('optional'=>true));
53         $mform->setDefault('timedue', time()+7*24*3600);
55         $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
57         $mform->addElement('select', 'preventlate', get_string('preventlate', 'assignment'), $ynoptions);
58         $mform->setDefault('preventlate', 0);
60         $this->coursemodule_grading_elements();
62         $typetitle = get_string('type'.$type, 'assignment');
64         // hack to support pluggable assignment type titles
65         if ($typetitle === '[[type'.$type.']]') {
66             $typetitle  = get_string('type'.$type, 'assignment_'.$type);
67         }
69         $mform->addElement('header', 'typedesc', $typetitle);
71         $assignmentinstance->setup_elements($mform);
73         $this->standard_coursemodule_elements();
75         $this->add_action_buttons();
76     }
78 }